package common.utils;

import java.util.Calendar;
import java.text.SimpleDateFormat;

public class DateTimeUtil {
	private static SimpleDateFormat dateformat;

	/**
	 * get now calenda
	 * @return
	 */
	private static Calendar getNow() {
		return Calendar.getInstance();
	}
	
	/**
	 * get Year of Sysdate
	 * 
	 * @return
	 */
	public static String getYear(){
		getNow().getTime();
		dateformat = new SimpleDateFormat("yyyy");		
		return dateformat.format(getNow().getTime());		
	}

	
	/**
	 * get Year of Sysdate, abbriviated
	 * eg. 08 for 2008
	 * @return
	 */
	public static String getYearinShort(){
		getNow();
		dateformat = new SimpleDateFormat("y");
		return dateformat.format(getNow().getTime());
	}

	/**
	 * get Month of Sysdate
	 * 
	 * @return
	 */
	public static String getMonth() {
		getNow();
		dateformat = new SimpleDateFormat("MM");
		return dateformat.format(getNow().getTime());
	}

	/**
	 * get Date of Sysdate
	 * 
	 * @return
	 */
	public static String getDate(){
		getNow();
		dateformat = new SimpleDateFormat("dd");
		return dateformat.format(getNow().getTime());
	}

	public static String getDay() {
		getNow();
		dateformat = new SimpleDateFormat("E");
		return dateformat.format(getNow().getTime());
	}

	/**
	 * get day of week in number eg. 1 for sunday, and so on
	 * 
	 * @return
	 */
	public static int getDayinNum() {
		getNow();
		int day = getNow().get(Calendar.DAY_OF_WEEK);

		return day;
	}

	/**
	 * 
	 * @return
	 */
	public static String getHour() {
		getNow();
		dateformat = new SimpleDateFormat("h");
		return dateformat.format(getNow().getTime());
	}

	/**
	 * 
	 * @return
	 */
	public static String getHour24() {
		getNow();
		dateformat = new SimpleDateFormat("H");
		return dateformat.format(getNow().getTime());
	}

	/**
	 * 
	 * @return
	 */
	public static String getMinute() {
		getNow();
		dateformat = new SimpleDateFormat("m");
		return dateformat.format(getNow().getTime());

	}

	/**
	 * 
	 * @return
	 */
	public static String getSecond() {
		getNow();
		dateformat = new SimpleDateFormat("s");
		return dateformat.format(getNow().getTime());
	}
	
	/**
	 * 
	 * @return
	 */
	public static String getMillisecond(){
		getNow();
		dateformat = new SimpleDateFormat("S");
		return dateformat.format(getNow().getTime());
	}

	/**
	 * 
	 * @return
	 */
	public static String getAmOrPM() {
		getNow();
		dateformat = new SimpleDateFormat("a");
		return dateformat.format(getNow().getTime());
	}
	
	/**
	 * 
	 * @return
	 */
	public static String getTimeZone(){
		getNow();
		dateformat = new SimpleDateFormat("z");
		return dateformat.format(getNow().getTime());
	}
	
	/**
	 * 
	 * @return
	 */
	public static String getTimeZoneRFC(){
		getNow();
		dateformat = new SimpleDateFormat("Z");
		return dateformat.format(getNow().getTime());
	}
	
	/**
	 * 
	 * @return
	 */
	public static String getWeekOfMonth(){
		getNow();
		dateformat = new SimpleDateFormat("F");
		return dateformat.format(getNow().getTime());
	}
	
	/**
	 * 
	 * @return
	 */
	public static String getWeekOfYear(){
		getNow();
		dateformat = new SimpleDateFormat("w");
		return dateformat.format(getNow().getTime());
	}

	/**
	 * 
	 * @return
	 */
	public static String getDayOfYear(){
		
		dateformat = new SimpleDateFormat("D");
		return dateformat.format(getNow().getTime());
	}
	
	
	/**
	 * @deprecated
	 * @return
	 */
	public static String getTimeformat(int format){
		StringBuffer sb = new StringBuffer();
		switch (format) {
		case 2:
			sb.append(getYear() + "-" + getMonth() + "-" + getDate());
			break;
		case 3:
			sb.append(getYear() + "-" + getMonth() + "-" + getDate());
			sb.append(" " + getHour() + ":" + getMinute() + ":" + getSecond());
			break;
		case 1:
			sb.append(getYear() + getMonth() + getDate());
			sb.append(" " + getHour() + getMinute() + getSecond());
			break;
		case 0:
		default:
			sb.append(getYear() + getMonth() + getDate());
			break;
		}

		return sb.toString();
	}
	
	/**
	 * @deprecated
	 * @return
	 */
	public static String getTimeformat(){
		return getTimeformat(0);
	}
	
	public static String addMonth(int n){
		
		
		return null;
	}
	
	
	
	
}
